package com.av.android;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


public class ReportAdapter extends ArrayAdapter<Report>
{
	final String[] statusarray = new String[]{"Detected","In Progress","Fixed","Friendly Location"};
	List<Report> data = null;
	Activity context = null;
	public ReportAdapter(Activity context, int resource, List<Report> list)
	{
		super(context, resource, list);
		this.context = context;
		this.data = list;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) 
	{   // Ordinary view in Spinner, we use android.R.layout.simple_spinner_item
		
		final Report report = getItem(position);
		View reportRow = context.getLayoutInflater().inflate(R.layout.report_row, null);
		reportRow.setClickable(true);
		reportRow.setOnClickListener(new OnClickListener() {
			
			public void onClick(View arg0) {
				context.startActivity(new Intent(context, ViewReportActivity.class).putExtra("report", report));
			}
		});
		TextView reportName = (TextView)reportRow.findViewById(R.id.report_name);
		TextView reportStatus = (TextView)reportRow.findViewById(R.id.report_status);
		TextView reportRate = (TextView)reportRow.findViewById(R.id.report_rate);
		TextView reportDate = (TextView)reportRow.findViewById(R.id.report_date);
		
		reportName.setText(report.getReportName());
		reportStatus.setText(statusarray[report.getStatus()]);
		reportRate.setText("Rate : "+report.getRate());
		reportDate.setText("Date : "+report.getCreated_on());
		
		
		return reportRow;
	}


}